import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Router, ActivatedRoute } from '@angular/router';
import { equalParamsAndUrlSegments } from '@angular/router/src/router_state';

@Component({
  selector: 'app-prescriptions-details',
  templateUrl: './prescriptions-details.component.html',
  styleUrls: ['./prescriptions-details.component.scss']
})
export class PrescriptionsDetailsComponent implements OnInit {
  id: string;
  list: any[] = [];
  constructor(private http: HttpClient, private activatedRoute: ActivatedRoute) { }

  ngOnInit() {
    this.activatedRoute.queryParams.subscribe(queryParams => {
			// 判断是事前还是事后的审方
			this.id = queryParams.infoMessage;
			// let title = queryParams.title;
    });
    this.http.get(window.API_ROOT + 'api/recipes/' + this.id ).subscribe((res: any) => {
      console.log('res_', res);
      const list =  res.data['药品信息'];
      list.forEach((element, index) => {
        const total = element['药品数量'] * element['药品单价'];
        element['合计']  = total.toFixed(2);
      });
      this.list = list;
    });
  }

}
